package com.lala.service.impl;

import com.lala.entity.ClientMessage;
import com.lala.dao.ClientMessageDao;
import com.lala.service.ClientMessageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (ClientMessage)表服务实现类
 *
 * @author makejava
 * @since 2020-03-24 11:12:29
 */
@Service("clientMessageService")
public class ClientMessageServiceImpl implements ClientMessageService {
    @Resource
    private ClientMessageDao clientMessageDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ClientMessage queryById(Integer id) {
        return this.clientMessageDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<ClientMessage> queryAllByLimit(int offset, int limit) {
        return this.clientMessageDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param clientMessage 实例对象
     * @return 实例对象
     */
    @Override
    public ClientMessage insert(ClientMessage clientMessage) {
        this.clientMessageDao.insert(clientMessage);
        return clientMessage;
    }

    /**
     * 修改数据
     *
     * @param clientMessage 实例对象
     * @return 实例对象
     */
    @Override
    public ClientMessage update(ClientMessage clientMessage) {
        this.clientMessageDao.update(clientMessage);
        return this.queryById(clientMessage.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.clientMessageDao.deleteById(id) > 0;
    }

    @Override
    public ClientMessage getMg(Integer loginId) {
        return clientMessageDao.getMg(loginId);
    }

    @Override
    public void updateMessage(ClientMessage clientMessage) {
        ClientMessage clientMessage1=clientMessageDao.getMg(clientMessage.getLoginId());
        clientMessage1.setIcon(clientMessage.getIcon());
        clientMessage1.setIdCard(clientMessage.getIdCard());
        clientMessage1.setRealName(clientMessage.getRealName());
        clientMessageDao.update(clientMessage1);
    }
}